<?php


abstract class BaseTutor extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $user_id;


	
	protected $firstname;


	
	protected $lastname;


	
	protected $rates;


	
	protected $servicearea_id;


	
	protected $additionalinfo;


	
	protected $updated_at;

	
	protected $asfGuardUser;

	
	protected $aServiceArea;

	
	protected $collSubjectTutors;

	
	protected $lastSubjectTutorCriteria = null;

	
	protected $collAvailabilityTutors;

	
	protected $lastAvailabilityTutorCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getUserId()
	{

		return $this->user_id;
	}

	
	public function getFirstname()
	{

		return $this->firstname;
	}

	
	public function getLastname()
	{

		return $this->lastname;
	}

	
	public function getRates()
	{

		return $this->rates;
	}

	
	public function getServiceareaId()
	{

		return $this->servicearea_id;
	}

	
	public function getAdditionalinfo()
	{

		return $this->additionalinfo;
	}

	
	public function getUpdatedAt($format = 'Y-m-d H:i:s')
	{

		if ($this->updated_at === null || $this->updated_at === '') {
			return null;
		} elseif (!is_int($this->updated_at)) {
						$ts = strtotime($this->updated_at);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse value of [updated_at] as date/time value: " . var_export($this->updated_at, true));
			}
		} else {
			$ts = $this->updated_at;
		}
		if ($format === null) {
			return $ts;
		} elseif (strpos($format, '%') !== false) {
			return strftime($format, $ts);
		} else {
			return date($format, $ts);
		}
	}

	
	public function setId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = TutorPeer::ID;
		}

	} 
	
	public function setUserId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->user_id !== $v) {
			$this->user_id = $v;
			$this->modifiedColumns[] = TutorPeer::USER_ID;
		}

		if ($this->asfGuardUser !== null && $this->asfGuardUser->getId() !== $v) {
			$this->asfGuardUser = null;
		}

	} 
	
	public function setFirstname($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->firstname !== $v) {
			$this->firstname = $v;
			$this->modifiedColumns[] = TutorPeer::FIRSTNAME;
		}

	} 
	
	public function setLastname($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->lastname !== $v) {
			$this->lastname = $v;
			$this->modifiedColumns[] = TutorPeer::LASTNAME;
		}

	} 
	
	public function setRates($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->rates !== $v) {
			$this->rates = $v;
			$this->modifiedColumns[] = TutorPeer::RATES;
		}

	} 
	
	public function setServiceareaId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->servicearea_id !== $v) {
			$this->servicearea_id = $v;
			$this->modifiedColumns[] = TutorPeer::SERVICEAREA_ID;
		}

		if ($this->aServiceArea !== null && $this->aServiceArea->getId() !== $v) {
			$this->aServiceArea = null;
		}

	} 
	
	public function setAdditionalinfo($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->additionalinfo !== $v) {
			$this->additionalinfo = $v;
			$this->modifiedColumns[] = TutorPeer::ADDITIONALINFO;
		}

	} 
	
	public function setUpdatedAt($v)
	{

		if ($v !== null && !is_int($v)) {
			$ts = strtotime($v);
			if ($ts === -1 || $ts === false) { 				throw new PropelException("Unable to parse date/time value for [updated_at] from input: " . var_export($v, true));
			}
		} else {
			$ts = $v;
		}
		if ($this->updated_at !== $ts) {
			$this->updated_at = $ts;
			$this->modifiedColumns[] = TutorPeer::UPDATED_AT;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->user_id = $rs->getInt($startcol + 1);

			$this->firstname = $rs->getString($startcol + 2);

			$this->lastname = $rs->getString($startcol + 3);

			$this->rates = $rs->getString($startcol + 4);

			$this->servicearea_id = $rs->getInt($startcol + 5);

			$this->additionalinfo = $rs->getString($startcol + 6);

			$this->updated_at = $rs->getTimestamp($startcol + 7, null);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Tutor object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TutorPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			TutorPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
    if ($this->isModified() && !$this->isColumnModified(TutorPeer::UPDATED_AT))
    {
      $this->setUpdatedAt(time());
    }

		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(TutorPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->asfGuardUser !== null) {
				if ($this->asfGuardUser->isModified()) {
					$affectedRows += $this->asfGuardUser->save($con);
				}
				$this->setsfGuardUser($this->asfGuardUser);
			}

			if ($this->aServiceArea !== null) {
				if ($this->aServiceArea->isModified()) {
					$affectedRows += $this->aServiceArea->save($con);
				}
				$this->setServiceArea($this->aServiceArea);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = TutorPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += TutorPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collSubjectTutors !== null) {
				foreach($this->collSubjectTutors as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collAvailabilityTutors !== null) {
				foreach($this->collAvailabilityTutors as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->asfGuardUser !== null) {
				if (!$this->asfGuardUser->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->asfGuardUser->getValidationFailures());
				}
			}

			if ($this->aServiceArea !== null) {
				if (!$this->aServiceArea->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aServiceArea->getValidationFailures());
				}
			}


			if (($retval = TutorPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collSubjectTutors !== null) {
					foreach($this->collSubjectTutors as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collAvailabilityTutors !== null) {
					foreach($this->collAvailabilityTutors as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TutorPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getUserId();
				break;
			case 2:
				return $this->getFirstname();
				break;
			case 3:
				return $this->getLastname();
				break;
			case 4:
				return $this->getRates();
				break;
			case 5:
				return $this->getServiceareaId();
				break;
			case 6:
				return $this->getAdditionalinfo();
				break;
			case 7:
				return $this->getUpdatedAt();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TutorPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getUserId(),
			$keys[2] => $this->getFirstname(),
			$keys[3] => $this->getLastname(),
			$keys[4] => $this->getRates(),
			$keys[5] => $this->getServiceareaId(),
			$keys[6] => $this->getAdditionalinfo(),
			$keys[7] => $this->getUpdatedAt(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = TutorPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setUserId($value);
				break;
			case 2:
				$this->setFirstname($value);
				break;
			case 3:
				$this->setLastname($value);
				break;
			case 4:
				$this->setRates($value);
				break;
			case 5:
				$this->setServiceareaId($value);
				break;
			case 6:
				$this->setAdditionalinfo($value);
				break;
			case 7:
				$this->setUpdatedAt($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = TutorPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setUserId($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setFirstname($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setLastname($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setRates($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setServiceareaId($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setAdditionalinfo($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setUpdatedAt($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(TutorPeer::DATABASE_NAME);

		if ($this->isColumnModified(TutorPeer::ID)) $criteria->add(TutorPeer::ID, $this->id);
		if ($this->isColumnModified(TutorPeer::USER_ID)) $criteria->add(TutorPeer::USER_ID, $this->user_id);
		if ($this->isColumnModified(TutorPeer::FIRSTNAME)) $criteria->add(TutorPeer::FIRSTNAME, $this->firstname);
		if ($this->isColumnModified(TutorPeer::LASTNAME)) $criteria->add(TutorPeer::LASTNAME, $this->lastname);
		if ($this->isColumnModified(TutorPeer::RATES)) $criteria->add(TutorPeer::RATES, $this->rates);
		if ($this->isColumnModified(TutorPeer::SERVICEAREA_ID)) $criteria->add(TutorPeer::SERVICEAREA_ID, $this->servicearea_id);
		if ($this->isColumnModified(TutorPeer::ADDITIONALINFO)) $criteria->add(TutorPeer::ADDITIONALINFO, $this->additionalinfo);
		if ($this->isColumnModified(TutorPeer::UPDATED_AT)) $criteria->add(TutorPeer::UPDATED_AT, $this->updated_at);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(TutorPeer::DATABASE_NAME);

		$criteria->add(TutorPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setUserId($this->user_id);

		$copyObj->setFirstname($this->firstname);

		$copyObj->setLastname($this->lastname);

		$copyObj->setRates($this->rates);

		$copyObj->setServiceareaId($this->servicearea_id);

		$copyObj->setAdditionalinfo($this->additionalinfo);

		$copyObj->setUpdatedAt($this->updated_at);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getSubjectTutors() as $relObj) {
				$copyObj->addSubjectTutor($relObj->copy($deepCopy));
			}

			foreach($this->getAvailabilityTutors() as $relObj) {
				$copyObj->addAvailabilityTutor($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new TutorPeer();
		}
		return self::$peer;
	}

	
	public function setsfGuardUser($v)
	{


		if ($v === null) {
			$this->setUserId(NULL);
		} else {
			$this->setUserId($v->getId());
		}


		$this->asfGuardUser = $v;
	}


	
	public function getsfGuardUser($con = null)
	{
		if ($this->asfGuardUser === null && ($this->user_id !== null)) {
						include_once 'plugins/sfGuardPlugin/lib/model/om/BasesfGuardUserPeer.php';

			$this->asfGuardUser = sfGuardUserPeer::retrieveByPK($this->user_id, $con);

			
		}
		return $this->asfGuardUser;
	}

	
	public function setServiceArea($v)
	{


		if ($v === null) {
			$this->setServiceareaId(NULL);
		} else {
			$this->setServiceareaId($v->getId());
		}


		$this->aServiceArea = $v;
	}


	
	public function getServiceArea($con = null)
	{
		if ($this->aServiceArea === null && ($this->servicearea_id !== null)) {
						include_once 'lib/model/om/BaseServiceAreaPeer.php';

			$this->aServiceArea = ServiceAreaPeer::retrieveByPK($this->servicearea_id, $con);

			
		}
		return $this->aServiceArea;
	}

	
	public function initSubjectTutors()
	{
		if ($this->collSubjectTutors === null) {
			$this->collSubjectTutors = array();
		}
	}

	
	public function getSubjectTutors($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseSubjectTutorPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSubjectTutors === null) {
			if ($this->isNew()) {
			   $this->collSubjectTutors = array();
			} else {

				$criteria->add(SubjectTutorPeer::TUTOR_ID, $this->getId());

				SubjectTutorPeer::addSelectColumns($criteria);
				$this->collSubjectTutors = SubjectTutorPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(SubjectTutorPeer::TUTOR_ID, $this->getId());

				SubjectTutorPeer::addSelectColumns($criteria);
				if (!isset($this->lastSubjectTutorCriteria) || !$this->lastSubjectTutorCriteria->equals($criteria)) {
					$this->collSubjectTutors = SubjectTutorPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastSubjectTutorCriteria = $criteria;
		return $this->collSubjectTutors;
	}

	
	public function countSubjectTutors($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseSubjectTutorPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(SubjectTutorPeer::TUTOR_ID, $this->getId());

		return SubjectTutorPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addSubjectTutor(SubjectTutor $l)
	{
		$this->collSubjectTutors[] = $l;
		$l->setTutor($this);
	}


	
	public function getSubjectTutorsJoinSubject($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseSubjectTutorPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collSubjectTutors === null) {
			if ($this->isNew()) {
				$this->collSubjectTutors = array();
			} else {

				$criteria->add(SubjectTutorPeer::TUTOR_ID, $this->getId());

				$this->collSubjectTutors = SubjectTutorPeer::doSelectJoinSubject($criteria, $con);
			}
		} else {
									
			$criteria->add(SubjectTutorPeer::TUTOR_ID, $this->getId());

			if (!isset($this->lastSubjectTutorCriteria) || !$this->lastSubjectTutorCriteria->equals($criteria)) {
				$this->collSubjectTutors = SubjectTutorPeer::doSelectJoinSubject($criteria, $con);
			}
		}
		$this->lastSubjectTutorCriteria = $criteria;

		return $this->collSubjectTutors;
	}

	
	public function initAvailabilityTutors()
	{
		if ($this->collAvailabilityTutors === null) {
			$this->collAvailabilityTutors = array();
		}
	}

	
	public function getAvailabilityTutors($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseAvailabilityTutorPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collAvailabilityTutors === null) {
			if ($this->isNew()) {
			   $this->collAvailabilityTutors = array();
			} else {

				$criteria->add(AvailabilityTutorPeer::TUTOR_ID, $this->getId());

				AvailabilityTutorPeer::addSelectColumns($criteria);
				$this->collAvailabilityTutors = AvailabilityTutorPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(AvailabilityTutorPeer::TUTOR_ID, $this->getId());

				AvailabilityTutorPeer::addSelectColumns($criteria);
				if (!isset($this->lastAvailabilityTutorCriteria) || !$this->lastAvailabilityTutorCriteria->equals($criteria)) {
					$this->collAvailabilityTutors = AvailabilityTutorPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastAvailabilityTutorCriteria = $criteria;
		return $this->collAvailabilityTutors;
	}

	
	public function countAvailabilityTutors($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseAvailabilityTutorPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(AvailabilityTutorPeer::TUTOR_ID, $this->getId());

		return AvailabilityTutorPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addAvailabilityTutor(AvailabilityTutor $l)
	{
		$this->collAvailabilityTutors[] = $l;
		$l->setTutor($this);
	}


	
	public function getAvailabilityTutorsJoinAvailability($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseAvailabilityTutorPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collAvailabilityTutors === null) {
			if ($this->isNew()) {
				$this->collAvailabilityTutors = array();
			} else {

				$criteria->add(AvailabilityTutorPeer::TUTOR_ID, $this->getId());

				$this->collAvailabilityTutors = AvailabilityTutorPeer::doSelectJoinAvailability($criteria, $con);
			}
		} else {
									
			$criteria->add(AvailabilityTutorPeer::TUTOR_ID, $this->getId());

			if (!isset($this->lastAvailabilityTutorCriteria) || !$this->lastAvailabilityTutorCriteria->equals($criteria)) {
				$this->collAvailabilityTutors = AvailabilityTutorPeer::doSelectJoinAvailability($criteria, $con);
			}
		}
		$this->lastAvailabilityTutorCriteria = $criteria;

		return $this->collAvailabilityTutors;
	}

} 